package com.itheima.zzyl.controller;

import com.itheima.zzyl.pojo.Result;
import com.itheima.zzyl.pojo.RoomType;
import com.itheima.zzyl.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/roomTypes")
public class RoomTypeController {
    @Autowired
    @Qualifier("roomTypeService")
    private RoomTypeService roomTypeService;

    @GetMapping
    @Cacheable(value = "roomTypeCache", key = "#userId+'_'+#status")
    public Result<Object> getRoomTypes(
            @RequestParam("userId") Integer userId,
            @RequestParam("status") Integer status
    ) {
        if (userId == null) {
            return Result.error("用户id不能为空");
        }
        List<RoomType> types = roomTypeService.getAllRoomType(status);
        return Result.success(types);
    }
}
